<?php
$rootUrl = '/~n00921103/webcourse/Final';
require_once (__DIR__ . '/password.php');
function GetConnection()
{
	global $password;
	$dbname='n00921103_db';
	$server='localhost';
	$port=3306; 
	$user='n00921103';
	$conn = new mysqli($server,$user, $password, $dbname,$port);
	return $conn;
}
function EscapeRow($row, $conn)
{
	$row2 = array();
	foreach ($row as $key => $value) {
		$row2[$key] = $conn->real_escape_string($value);
	}
	return $row2;
}
function curl_download($Url){ 
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $Url);
    // Include header in result? (0 = yes, 1 = no)
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}
function genSelectInput($prefix, $fieldName, $labelText, $selectOptions)
{
	echo 				"<div class=\"control-group\">";
	echo				"<label class=\"control-label\" for=\"$prefix" . "_" . "$fieldName\">$labelText:</label>";
	echo					"<div class=\"controls\">";
	echo 						"<select id=\"$prefix" . "_" . "$fieldName\">";
	for ($i=0; $i < count($selectOptions); $i++) {
		echo 						"<option value=\"" . $selectOptions[$i]['value'] . "\" >" . $selectOptions[$i]['label'] . "</option>"; 
	}			 			  
	echo 						"</select>"; 
	echo					"</div>";
	echo				"</div>";	
}

function genTextInput($prefix,$fieldName,$labelText,$type)
{
	if (!isset($type) )
		$type='text';
	echo			"<div class=\"control-group\">";
	echo			"<label class=\"control-label\" for=\"$prefix" . '_' . "$fieldName\">$labelText:</label>";
	echo				"<div class=\"controls\">";
	echo 					"<input type=\"$type\" id=\"$prefix" . '_' . "$fieldName\" value=\"\" />";
	echo				"</div>";
	echo			"</div>";	
}
function genAddrInputs($prefix)
{
	/* first name */
	genTextInput($prefix,"firstName","First Name",'');
	
	/* last name */
	genTextInput($prefix,"lastName","Last Name",'');

	/* address line 1 */
	genTextInput($prefix,"line_1","Line 1",'');
		
	/* address line 2 */
	genTextInput($prefix,"line_2","Line 2",'');

	/* city */				
	genTextInput($prefix,"city","City",'');

	/* state */				
	genTextInput($prefix,"state","State",'');

	/* zip */	
	genTextInput($prefix,"zip","Zip Code",'');
	
	/* tel */
	genTextInput($prefix,"tel","Phone Number","tel");
}
function makeKwdArray($parent) 
{
	$results=Keywords::GetChildren($parent);
	$i=0;
	while ($row = $results->fetch_assoc())
	{
		$array[$i]['label']=$row['name'];
		$array[$i]['value']=$row['id'];
		$i++;
	}
	return $array;
}
